package com.flycent.hqhs.ui;

import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.flycent.hqhs.R;
import com.flycent.hqhs.ui.view.MyScrollLayout;
import com.flycent.hqhs.ui.view.OnViewChangeListener;
import com.flycent.hqhs.util.ContextUtil;

/**
 * @author fbl
 *  欢迎界面
 */
public class WelcomeActivity extends BaseActivity implements OnViewChangeListener{


	private MyScrollLayout mScrollLayout;
	private ImageView[] imgs;
	private int count;
	private int currentItem;
	private ImageView finishview;
	@SuppressWarnings("unused")
	private RelativeLayout mainRLayout;
	private LinearLayout pointLLayout;
	SharedPreferences Preferences;
	private Button startButton;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.activity_welcome);
		initView();

	}

	private void initView() {
		mScrollLayout  = (MyScrollLayout) findViewById(R.id.ScrollLayout);
		pointLLayout = (LinearLayout) findViewById(R.id.llayout);
		mainRLayout = (RelativeLayout) findViewById(R.id.mainRLayout);
		finishview = (ImageView) findViewById(R.id.finish);
		startButton  = (Button) findViewById(R.id.startBtn);
		

		finishview.setOnClickListener(onClick);
		startButton.setOnClickListener(onClick);

		count = mScrollLayout.getChildCount();
		imgs = new ImageView[count];
		for(int i = 0; i< count;i++) {
			imgs[i] = (ImageView) pointLLayout.getChildAt(i);
			imgs[i].setEnabled(true);
			imgs[i].setTag(i);
		}
		currentItem = 0;
		imgs[currentItem].setEnabled(false);
		mScrollLayout.SetOnViewChangeListener(this);
	}

	private View.OnClickListener onClick = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.finish:
				ContextUtil.startActivity(WelcomeActivity.this,MainTabActivity.class);
				finish();
				break;
			case R.id.startBtn:
				ContextUtil.startActivity(WelcomeActivity.this,MainTabActivity.class);
				finish();
				break;
			default:
				break;
			}
		}
	};  

	@Override
	public void OnViewChange(int position) {
		setcurrentPoint(position);
	}

	private void setcurrentPoint(int position) {
		if(position < 0 || position > count -1 || currentItem == position) {
			return;
		}
		imgs[currentItem].setEnabled(true);
		imgs[position].setEnabled(false);
		currentItem = position;
	}


}
